﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class RFReceiptDetailBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IInvTransDA invTransDA = DataAccess.CreateInvTransDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private PubParasInfo pubParasInfo;
        private static readonly IReceiptDA receiptDA = DataAccess.CreateReceiptDA();
        private static readonly IReceiptDetailDA receiptDetailDA = DataAccess.CreateReceiptDetailDA();
        private static readonly IReceiptDetailLpnDA receiptDetailLpnDA = DataAccess.CreateReceiptDetailLpnDA();
        private static readonly IRFInboundDA rfInboundDA = DataAccess.CreateRFInboundDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly ITaskDetailDA taskDetailDA = DataAccess.CreateTaskDetailDA();

        public RFReceiptDetailBLL()
        {
            this.pubParasInfo = null;
        }

        public RFReceiptDetailBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public RFReceiptDetailBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string BatchExecPutawayByLpn(string toLoc, List<string> lpnID)
        {
            string whLoginID = this.dataBaseID[0];
            string result = string.Empty;
            string message = string.Empty;
            List<PutawayDetailInfo> putawayDetailInfoList = new List<PutawayDetailInfo>();
            List<string> moveableLpnIDList = new List<string>();
            for (int i = 0; i < lpnID.Count; i++)
            {
                try
                {
                    List<PutawayDetailInfo> putawayDetailInfos = null;
                    RFPutawayInfo rfPutawayInfo = this.GetRFPutawayInfoByLpn(lpnID[i]);
                    if (rfPutawayInfo != null)
                    {
                        rfPutawayInfo.FinalToLoc = toLoc;
                        putawayDetailInfos = this.ExchangeRFPutawayInfo(rfPutawayInfo);
                        for (int j = 0; j < putawayDetailInfos.Count; j++)
                        {
                            PutawayDetailInfo putawayDetailInfo = putawayDetailInfos[j];
                            putawayDetailInfoList.Add(putawayDetailInfo);
                        }
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    result = result + "  " + lpnID[i];
                }
            }
            if (!string.IsNullOrEmpty(message))
            {
                return (message + result);
            }
            if ((putawayDetailInfoList != null) && (putawayDetailInfoList.Count > 0))
            {
                result = new ReceiptDetailBLL(this.pubParasInfo).ConfirmPutAway(putawayDetailInfoList);
            }
            if ((moveableLpnIDList != null) && (moveableLpnIDList.Count > 0))
            {
                RFInventoryMgtBLL rfInventoryMgtBLL = new RFInventoryMgtBLL(this.pubParasInfo);
                return rfInventoryMgtBLL.ExecInvMoveByLpnList(moveableLpnIDList, toLoc);
            }
            return "";
        }

        public List<PutawayDetailInfo> ExchangeRFPutawayInfo(RFPutawayInfo rfPutawayInfo)
        {
            List<PutawayDetailInfo> putawayDetailInfos = new List<PutawayDetailInfo>();
            for (int i = 0; i < rfPutawayInfo.RFPutawayDetailInfos.Count; i++)
            {
                PutawayDetailInfo putawayDetailInfo = new PutawayDetailInfo {
                    TaskDetailID = rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID,
                    FromLoc = rfPutawayInfo.RFPutawayDetailInfos[i].FromLoc,
                    FinalLoc = rfPutawayInfo.FinalToLoc,
                    FromLpnID = rfPutawayInfo.LpnID,
                    LpnID = rfPutawayInfo.LpnID,
                    LotID = rfPutawayInfo.RFPutawayDetailInfos[i].LotID,
                    OwnerID = rfPutawayInfo.RFPutawayDetailInfos[i].OwnerID,
                    PackID = rfPutawayInfo.RFPutawayDetailInfos[i].PackID,
                    Qty = rfPutawayInfo.RFPutawayDetailInfos[i].Qty,
                    ReceiptID = rfPutawayInfo.RFPutawayDetailInfos[i].ReceiptID,
                    ReceiptLineID = rfPutawayInfo.RFPutawayDetailInfos[i].ReceiptLineID,
                    SkuID = rfPutawayInfo.RFPutawayDetailInfos[i].SkuID,
                    UomID = rfPutawayInfo.RFPutawayDetailInfos[i].UomID,
                    UpdatedBy = this.pubParasInfo.UserID
                };
                TaskDetailInfo taskDetailInfo = taskDetailDA.GetTaskDetailByID(rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID, this.dataBaseID[0], this.pubParasInfo);
                putawayDetailInfo.SuggestLoc = taskDetailInfo.ToLoc;
                putawayDetailInfos.Add(putawayDetailInfo);
            }
            return putawayDetailInfos;
        }

        private ReceiptDetailInfo ExchangeRfReceiptDetailInfo2ReceiptDetailInfo(RFReceiptDetailInfo rfReceiptDetailInfo, ReceiptDetailInfo receiptDetailInfo, ReceiptDetailBLL receiptDetailBLL, string whLoginID)
        {
            receiptDetailInfo.RowID = rfReceiptDetailInfo.RowID;
            receiptDetailInfo.WhID = rfReceiptDetailInfo.WhID;
            receiptDetailInfo.ReceiptID = rfReceiptDetailInfo.ReceiptID;
            receiptDetailInfo.ReceiptLineID = rfReceiptDetailInfo.ReceiptLineID;
            receiptDetailInfo.OwnerID = rfReceiptDetailInfo.OwnerID;
            receiptDetailInfo.PoID = rfReceiptDetailInfo.PoID;
            receiptDetailInfo.PoLineID = rfReceiptDetailInfo.PoLineID;
            receiptDetailInfo.SkuID = rfReceiptDetailInfo.SkuID;
            receiptDetailInfo.SkuDescr = rfReceiptDetailInfo.SkuDescr;
            receiptDetailInfo.LpnID = rfReceiptDetailInfo.LpnID;
            receiptDetailInfo.CaseID = rfReceiptDetailInfo.CaseID;
            receiptDetailInfo.Status = string.IsNullOrEmpty(rfReceiptDetailInfo.Status) ? ReceiptStatus.New : rfReceiptDetailInfo.Status;
            receiptDetailInfo.StatusD = rfReceiptDetailInfo.StatusD;
            receiptDetailInfo.ReceivedDate = DateTime.Now;
            receiptDetailInfo.ExpectedQty = rfReceiptDetailInfo.ExpectedQty;
            receiptDetailInfo.ReceivedQty = rfReceiptDetailInfo.ReceivedQty;
            receiptDetailInfo.AdjustedQty = rfReceiptDetailInfo.AdjustedQty;
            receiptDetailInfo.RejectedQty = rfReceiptDetailInfo.RejectedQty;
            receiptDetailInfo.PackID = rfReceiptDetailInfo.PackID;
            receiptDetailInfo.UomID = rfReceiptDetailInfo.UomID;
            if (string.IsNullOrEmpty(rfReceiptDetailInfo.UomID))
            {
                PackInfo packInfo = packDA.GetPackByID(rfReceiptDetailInfo.PackID, whLoginID);
                if (packInfo != null)
                {
                    receiptDetailInfo.UomID = packInfo.PackUom1;
                }
            }
            receiptDetailInfo.ToLoc = string.IsNullOrEmpty(rfReceiptDetailInfo.ToLoc) ? "Stage" : rfReceiptDetailInfo.ToLoc;
            receiptDetailInfo.ToLot = rfReceiptDetailInfo.ToLot;
            receiptDetailInfo.ToLpnID = rfReceiptDetailInfo.ToLpnID;
            receiptDetailInfo.ConditionCode = string.IsNullOrEmpty(rfReceiptDetailInfo.ConditionCode) ? "OK" : rfReceiptDetailInfo.ConditionCode;
            receiptDetailInfo.VendorID = rfReceiptDetailInfo.VendorID;
            receiptDetailInfo.VendorName = rfReceiptDetailInfo.VendorName;
            if (receiptDetailInfo.ReceiptLot == null)
            {
                receiptDetailInfo.ReceiptLot = new ReceiptLotInfo();
            }
            receiptDetailInfo.ReceiptLot.LotAttr01 = rfReceiptDetailInfo.LotAttr01;
            receiptDetailInfo.ReceiptLot.LotAttr02 = rfReceiptDetailInfo.LotAttr02;
            receiptDetailInfo.ReceiptLot.LotAttr03 = rfReceiptDetailInfo.LotAttr03;
            receiptDetailInfo.ReceiptLot.LotAttr04 = rfReceiptDetailInfo.LotAttr04;
            receiptDetailInfo.ReceiptLot.LotAttr05 = rfReceiptDetailInfo.LotAttr05;
            receiptDetailInfo.ReceiptLot.LotAttr06 = rfReceiptDetailInfo.LotAttr06;
            receiptDetailInfo.ReceiptLot.LotAttr07 = rfReceiptDetailInfo.LotAttr07;
            receiptDetailInfo.ReceiptLot.LotAttr08 = rfReceiptDetailInfo.LotAttr08;
            receiptDetailInfo.ReceiptLot.LotAttr09 = rfReceiptDetailInfo.LotAttr09;
            receiptDetailInfo.ReceiptLot.LotAttr10 = rfReceiptDetailInfo.LotAttr10;
            receiptDetailInfo.ReceiptLot.ProduceDate = rfReceiptDetailInfo.LotProduceDate;
            receiptDetailInfo.ReceiptLot.ExpiryDate = rfReceiptDetailInfo.LotExpiryDate;
            receiptDetailInfo.ReceiptLot.ReceiptDate = DateTime.Now;
            receiptDetailInfo.ReceiptLot.ExternalLot = rfReceiptDetailInfo.LotExternalLot;
            if (string.IsNullOrEmpty(rfReceiptDetailInfo.LotVendorID))
            {
                receiptDetailInfo.ReceiptLot.VendorID = rfReceiptDetailInfo.VendorID;
            }
            else
            {
                receiptDetailInfo.ReceiptLot.VendorID = rfReceiptDetailInfo.LotVendorID;
            }
            receiptDetailInfo.Remark = rfReceiptDetailInfo.Remark;
            receiptDetailInfo.FromLoc = receiptDetailInfo.ToLoc;
            receiptDetailInfo.FromLpnID = receiptDetailInfo.ToLpnID;
            if (!receiptDetailBLL.CheckMandatoryLotAttribute(receiptDetailInfo, whLoginID))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_022", this.pubParasInfo.UserLanguage);
            }
            return receiptDetailInfo;
        }

        public string ExecPutawayByLpn(RFPutawayInfo rfPutawayInfo)
        {
            string result = string.Empty;
            string finalToLoc = rfPutawayInfo.FinalToLoc;
            if (!string.IsNullOrEmpty(rfPutawayInfo.ToLoc))
            {
                RFPutawayInfo putawayInfo = this.GetRFPutawayInfoByLpn(rfPutawayInfo.LpnID);
                putawayInfo.FinalToLoc = rfPutawayInfo.FinalToLoc;
                List<PutawayDetailInfo> putawayDetailInfos = this.ExchangeRFPutawayInfo(putawayInfo);
                result = new ReceiptDetailBLL(this.pubParasInfo).ConfirmPutAway(putawayDetailInfos);
            }
            return result;
        }

        public bool ExecReceivingByAsnLpn(RFReceiptDetailInfo rfReceiptDetailInfo)
        {
            string result = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving' OR RD.STATUS = 'ReceivedComplete') AND RD.OWNER_ID = '" + rfReceiptDetailInfo.OwnerID + "' AND RD.SKU_ID = '" + rfReceiptDetailInfo.SkuID + "' ";
            ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(rfReceiptDetailInfo.ReceiptID, whLoginID, this.pubParasInfo);
            List<ReceiptDetailInfo> receiptDetailInfos = null;
            if (receiptInfo.IsPalletized == "Y")
            {
                receiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(rfReceiptDetailInfo.ReceiptID, where, whLoginID, this.pubParasInfo);
            }
            else
            {
                receiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(rfReceiptDetailInfo.ReceiptID, where, whLoginID, this.pubParasInfo);
            }
            if ((receiptDetailInfos != null) && (receiptDetailInfos.Count > 0))
            {
                LotTemplateInfo lotTemplateInfo = commonMethod.GetAttributeInfoBySkuID(rfReceiptDetailInfo.SkuID, rfReceiptDetailInfo.OwnerID, whLoginID);
                List<ReceiptDetailInfo> execReceiptDetailInfoList = new List<ReceiptDetailInfo>();
                decimal rfTotalReceivedQty = rfReceiptDetailInfo.ReceivedQty;
                for (int i = 0; i < receiptDetailInfos.Count; i++)
                {
                    if (rfTotalReceivedQty <= 0M)
                    {
                        break;
                    }
                    if (receiptDetailInfos[i].ReceivedQty < receiptDetailInfos[i].ExpectedQty)
                    {
                        decimal availReceivedQty = receiptDetailInfos[i].ExpectedQty - receiptDetailInfos[i].ReceivedQty;
                        if (availReceivedQty < rfTotalReceivedQty)
                        {
                            rfTotalReceivedQty -= availReceivedQty;
                        }
                        else
                        {
                            availReceivedQty = rfTotalReceivedQty;
                            rfTotalReceivedQty = 0M;
                        }
                        ReceiptDetailInfo execReceiptDetailInfo = new ReceiptDetailInfo {
                            RowID = receiptDetailInfos[i].RowID,
                            WhID = receiptDetailInfos[i].WhID,
                            ReceiptID = rfReceiptDetailInfo.ReceiptID,
                            ReceiptLineID = receiptDetailInfos[i].ReceiptLineID,
                            OwnerID = rfReceiptDetailInfo.OwnerID,
                            PoID = receiptDetailInfos[i].PoID,
                            PoLineID = receiptDetailInfos[i].PoLineID,
                            SkuID = rfReceiptDetailInfo.SkuID,
                            SkuDescr = rfReceiptDetailInfo.SkuDescr,
                            LpnID = rfReceiptDetailInfo.ToLpnID,
                            CaseID = rfReceiptDetailInfo.CaseID,
                            Status = receiptDetailInfos[i].Status,
                            StatusD = receiptDetailInfos[i].StatusD,
                            ReceivedDate = DateTime.Now,
                            ExpectedQty = receiptDetailInfos[i].ExpectedQty,
                            ReceivedQty = availReceivedQty,
                            AdjustedQty = receiptDetailInfos[i].AdjustedQty,
                            RejectedQty = receiptDetailInfos[i].RejectedQty,
                            PackID = receiptDetailInfos[i].PackID,
                            UomID = receiptDetailInfos[i].UomID,
                            ToLoc = string.IsNullOrEmpty(rfReceiptDetailInfo.ToLoc) ? "Stage" : rfReceiptDetailInfo.ToLoc,
                            ToLot = rfReceiptDetailInfo.ToLot,
                            ToLpnID = rfReceiptDetailInfo.ToLpnID,
                            ConditionCode = string.IsNullOrEmpty(rfReceiptDetailInfo.ConditionCode) ? "OK" : rfReceiptDetailInfo.ConditionCode,
                            VendorID = rfReceiptDetailInfo.VendorID,
                            VendorName = rfReceiptDetailInfo.VendorName
                        };
                        if (execReceiptDetailInfo.ReceiptLot == null)
                        {
                            execReceiptDetailInfo.ReceiptLot = new ReceiptLotInfo();
                        }
                        if (lotTemplateInfo != null)
                        {
                            if ((lotTemplateInfo.RfLotAttr01Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr01))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr01 = receiptDetailInfos[i].ReceiptLot.LotAttr01;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr01 = rfReceiptDetailInfo.LotAttr01;
                            }
                            if ((lotTemplateInfo.RfLotAttr02Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr02))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr02 = receiptDetailInfos[i].ReceiptLot.LotAttr02;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr02 = rfReceiptDetailInfo.LotAttr02;
                            }
                            if ((lotTemplateInfo.RfLotAttr03Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr03))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr03 = receiptDetailInfos[i].ReceiptLot.LotAttr03;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr03 = rfReceiptDetailInfo.LotAttr03;
                            }
                            if ((lotTemplateInfo.RfLotAttr04Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr04))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr04 = receiptDetailInfos[i].ReceiptLot.LotAttr04;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr04 = rfReceiptDetailInfo.LotAttr04;
                            }
                            if ((lotTemplateInfo.RfLotAttr05Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr05))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr05 = receiptDetailInfos[i].ReceiptLot.LotAttr05;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr05 = rfReceiptDetailInfo.LotAttr05;
                            }
                            if ((lotTemplateInfo.RfLotAttr06Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr06))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr06 = receiptDetailInfos[i].ReceiptLot.LotAttr06;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr06 = rfReceiptDetailInfo.LotAttr06;
                            }
                            if ((lotTemplateInfo.RfLotAttr07Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr07))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr07 = receiptDetailInfos[i].ReceiptLot.LotAttr07;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr07 = rfReceiptDetailInfo.LotAttr07;
                            }
                            if ((lotTemplateInfo.RfLotAttr08Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr08))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr08 = receiptDetailInfos[i].ReceiptLot.LotAttr08;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr08 = rfReceiptDetailInfo.LotAttr08;
                            }
                            execReceiptDetailInfo.ReceiptLot.LotAttr09 = rfReceiptDetailInfo.LotAttr09;
                            if ((lotTemplateInfo.RfLotAttr10Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr10))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr10 = receiptDetailInfos[i].ReceiptLot.LotAttr10;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr10 = rfReceiptDetailInfo.LotAttr10;
                            }
                            if (lotTemplateInfo.RfProduceDateVisible != "Y")
                            {
                                execReceiptDetailInfo.ReceiptLot.ProduceDate = receiptDetailInfos[i].ReceiptLot.ProduceDate;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ProduceDate = rfReceiptDetailInfo.LotProduceDate;
                            }
                            if (lotTemplateInfo.RfExpiryDateVisible != "Y")
                            {
                                execReceiptDetailInfo.ReceiptLot.ExpiryDate = receiptDetailInfos[i].ReceiptLot.ExpiryDate;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ExpiryDate = rfReceiptDetailInfo.LotExpiryDate;
                            }
                            if ((lotTemplateInfo.RfExternalLotVisible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotExternalLot))
                            {
                                execReceiptDetailInfo.ReceiptLot.ExternalLot = receiptDetailInfos[i].ReceiptLot.ExternalLot;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ExternalLot = rfReceiptDetailInfo.LotExternalLot;
                            }
                        }
                        else
                        {
                            execReceiptDetailInfo.ReceiptLot.LotAttr01 = rfReceiptDetailInfo.LotAttr01;
                            execReceiptDetailInfo.ReceiptLot.LotAttr02 = rfReceiptDetailInfo.LotAttr02;
                            execReceiptDetailInfo.ReceiptLot.LotAttr03 = rfReceiptDetailInfo.LotAttr03;
                            execReceiptDetailInfo.ReceiptLot.LotAttr04 = rfReceiptDetailInfo.LotAttr04;
                            execReceiptDetailInfo.ReceiptLot.LotAttr05 = rfReceiptDetailInfo.LotAttr05;
                            execReceiptDetailInfo.ReceiptLot.LotAttr06 = rfReceiptDetailInfo.LotAttr06;
                            execReceiptDetailInfo.ReceiptLot.LotAttr07 = rfReceiptDetailInfo.LotAttr07;
                            execReceiptDetailInfo.ReceiptLot.LotAttr08 = rfReceiptDetailInfo.LotAttr08;
                            execReceiptDetailInfo.ReceiptLot.LotAttr09 = rfReceiptDetailInfo.LotAttr09;
                            execReceiptDetailInfo.ReceiptLot.LotAttr10 = rfReceiptDetailInfo.LotAttr10;
                            execReceiptDetailInfo.ReceiptLot.ProduceDate = rfReceiptDetailInfo.LotProduceDate;
                            execReceiptDetailInfo.ReceiptLot.ExpiryDate = rfReceiptDetailInfo.LotExpiryDate;
                            execReceiptDetailInfo.ReceiptLot.ExternalLot = rfReceiptDetailInfo.LotExternalLot;
                        }
                        execReceiptDetailInfo.ReceiptLot.ReceiptDate = DateTime.Now;
                        if (string.IsNullOrEmpty(receiptDetailInfos[i].VendorID))
                        {
                            execReceiptDetailInfo.ReceiptLot.VendorID = rfReceiptDetailInfo.VendorID;
                        }
                        else
                        {
                            execReceiptDetailInfo.ReceiptLot.VendorID = receiptDetailInfos[i].VendorID;
                        }
                        execReceiptDetailInfo.Remark = rfReceiptDetailInfo.Remark;
                        execReceiptDetailInfo.EffectiveDate = DateTime.Now;
                        execReceiptDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                        execReceiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                        execReceiptDetailInfo.FromLoc = execReceiptDetailInfo.ToLoc;
                        execReceiptDetailInfo.FromLpnID = execReceiptDetailInfo.ToLpnID;
                        execReceiptDetailInfoList.Add(execReceiptDetailInfo);
                    }
                }
                if (rfTotalReceivedQty > 0M)
                {
                    ReceiptDetailInfo local1 = execReceiptDetailInfoList[execReceiptDetailInfoList.Count - 1];
                    local1.ReceivedQty += rfTotalReceivedQty;
                }
                if ((execReceiptDetailInfoList != null) && (execReceiptDetailInfoList.Count > 0))
                {
                    result = new ReceiptDetailBLL(this.pubParasInfo).ExecuteReceiving(receiptInfo, execReceiptDetailInfoList);
                }
            }
            return !string.IsNullOrEmpty(result);
        }

        public bool ExecReceivingByAsnLpnForYT(RFReceiptDetailInfo rfReceiptDetailInfo)
        {
            string whLoginID = this.dataBaseID[0];
            string where = " WHERE IT.TRANS_TYPE = 'IN' AND IT.SOURCE_TRANS_TYPE = 'ReceiptDetailAdd' AND IT.STATUS = 'OK' AND IT.LOT_ATTR05 = '" + rfReceiptDetailInfo.LotAttr05 + "'";
            if (invTransDA.GetInvTransByWhere(where, whLoginID, this.pubParasInfo) != null)
            {
                throw new Exception(" 系统已经存在序列号：" + rfReceiptDetailInfo.LotAttr05);
            }
            if (rfReceiptDetailInfo.ReceiptType == "Blind")
            {
                List<RFReceiptDetailInfo> rfReceiptDetailInfos = new List<RFReceiptDetailInfo> {
                    rfReceiptDetailInfo
                };
                return this.ExecReceivingByLpn(rfReceiptDetailInfo.ReceiptID, rfReceiptDetailInfos);
            }
            return this.ExecReceivingByAsnLpn(rfReceiptDetailInfo);
        }

        public bool ExecReceivingByAsnLpnLot(RFReceiptDetailInfo rfReceiptDetailInfo)
        {
            string result = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving') AND RD.OWNER_ID = '" + rfReceiptDetailInfo.OwnerID + "' AND RD.SKU_ID = '" + rfReceiptDetailInfo.SkuID + "' ";
            if (!string.IsNullOrEmpty(rfReceiptDetailInfo.LotExternalLot))
            {
                where = where + " AND RD.EXTERNAL_LOT = '" + rfReceiptDetailInfo.LotExternalLot + "'";
            }
            if (!string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr01))
            {
                where = where + " AND RD.LOT_ATTR01 = '" + rfReceiptDetailInfo.LotAttr01 + "'";
            }
            ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(rfReceiptDetailInfo.ReceiptID, whLoginID, this.pubParasInfo);
            List<ReceiptDetailInfo> receiptDetailInfos = null;
            if (receiptInfo.IsPalletized == "Y")
            {
                receiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(rfReceiptDetailInfo.ReceiptID, where, whLoginID, this.pubParasInfo);
            }
            else
            {
                receiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(rfReceiptDetailInfo.ReceiptID, where, whLoginID, this.pubParasInfo);
            }
            if ((receiptDetailInfos != null) && (receiptDetailInfos.Count > 0))
            {
                LotTemplateInfo lotTemplateInfo = commonMethod.GetAttributeInfoBySkuID(rfReceiptDetailInfo.SkuID, rfReceiptDetailInfo.OwnerID, whLoginID);
                PackInfo packInfo = packDA.GetPackByID(rfReceiptDetailInfo.PackID, whLoginID);
                List<ReceiptDetailInfo> execReceiptDetailInfoList = new List<ReceiptDetailInfo>();
                decimal rfTotalReceivedQty = rfReceiptDetailInfo.ReceivedQty;
                for (int i = 0; i < receiptDetailInfos.Count; i++)
                {
                    if (rfTotalReceivedQty <= 0M)
                    {
                        break;
                    }
                    if (receiptDetailInfos[i].ReceivedQty < receiptDetailInfos[i].ExpectedQty)
                    {
                        decimal availReceivedQty = receiptDetailInfos[i].ExpectedQty - receiptDetailInfos[i].ReceivedQty;
                        if (availReceivedQty < rfTotalReceivedQty)
                        {
                            rfTotalReceivedQty -= availReceivedQty;
                        }
                        else
                        {
                            availReceivedQty = rfTotalReceivedQty;
                            rfTotalReceivedQty = 0M;
                        }
                        ReceiptDetailInfo execReceiptDetailInfo = new ReceiptDetailInfo {
                            RowID = receiptDetailInfos[i].RowID,
                            WhID = receiptDetailInfos[i].WhID,
                            ReceiptID = rfReceiptDetailInfo.ReceiptID,
                            ReceiptLineID = receiptDetailInfos[i].ReceiptLineID,
                            OwnerID = rfReceiptDetailInfo.OwnerID,
                            PoID = receiptDetailInfos[i].PoID,
                            PoLineID = receiptDetailInfos[i].PoLineID,
                            SkuID = rfReceiptDetailInfo.SkuID,
                            SkuDescr = rfReceiptDetailInfo.SkuDescr,
                            LpnID = rfReceiptDetailInfo.ToLpnID,
                            CaseID = rfReceiptDetailInfo.CaseID,
                            Status = receiptDetailInfos[i].Status,
                            StatusD = receiptDetailInfos[i].StatusD,
                            ReceivedDate = DateTime.Now,
                            ExpectedQty = receiptDetailInfos[i].ExpectedQty,
                            ReceivedQty = availReceivedQty,
                            AdjustedQty = receiptDetailInfos[i].AdjustedQty,
                            RejectedQty = receiptDetailInfos[i].RejectedQty,
                            PackID = receiptDetailInfos[i].PackID
                        };
                        if (!((packInfo == null) || string.IsNullOrEmpty(packInfo.PackUom1)))
                        {
                            execReceiptDetailInfo.UomID = packInfo.PackUom1;
                        }
                        else
                        {
                            execReceiptDetailInfo.UomID = receiptDetailInfos[i].UomID;
                        }
                        execReceiptDetailInfo.ToLoc = string.IsNullOrEmpty(rfReceiptDetailInfo.ToLoc) ? "Stage" : rfReceiptDetailInfo.ToLoc;
                        execReceiptDetailInfo.ToLot = rfReceiptDetailInfo.ToLot;
                        execReceiptDetailInfo.ToLpnID = rfReceiptDetailInfo.ToLpnID;
                        execReceiptDetailInfo.ConditionCode = string.IsNullOrEmpty(rfReceiptDetailInfo.ConditionCode) ? "OK" : rfReceiptDetailInfo.ConditionCode;
                        execReceiptDetailInfo.VendorID = rfReceiptDetailInfo.VendorID;
                        execReceiptDetailInfo.VendorName = rfReceiptDetailInfo.VendorName;
                        if (execReceiptDetailInfo.ReceiptLot == null)
                        {
                            execReceiptDetailInfo.ReceiptLot = new ReceiptLotInfo();
                        }
                        if (lotTemplateInfo != null)
                        {
                            if ((lotTemplateInfo.RfLotAttr01Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr01))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr01 = receiptDetailInfos[i].ReceiptLot.LotAttr01;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr01 = rfReceiptDetailInfo.LotAttr01;
                            }
                            if ((lotTemplateInfo.RfLotAttr02Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr02))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr02 = receiptDetailInfos[i].ReceiptLot.LotAttr02;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr02 = rfReceiptDetailInfo.LotAttr02;
                            }
                            if ((lotTemplateInfo.RfLotAttr03Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr03))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr03 = receiptDetailInfos[i].ReceiptLot.LotAttr03;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr03 = rfReceiptDetailInfo.LotAttr03;
                            }
                            if ((lotTemplateInfo.RfLotAttr04Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr04))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr04 = receiptDetailInfos[i].ReceiptLot.LotAttr04;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr04 = rfReceiptDetailInfo.LotAttr04;
                            }
                            if ((lotTemplateInfo.RfLotAttr05Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr05))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr05 = receiptDetailInfos[i].ReceiptLot.LotAttr05;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr05 = rfReceiptDetailInfo.LotAttr05;
                            }
                            if ((lotTemplateInfo.RfLotAttr06Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr06))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr06 = receiptDetailInfos[i].ReceiptLot.LotAttr06;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr06 = rfReceiptDetailInfo.LotAttr06;
                            }
                            if ((lotTemplateInfo.RfLotAttr07Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr07))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr07 = receiptDetailInfos[i].ReceiptLot.LotAttr07;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr07 = rfReceiptDetailInfo.LotAttr07;
                            }
                            if ((lotTemplateInfo.RfLotAttr08Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr08))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr08 = receiptDetailInfos[i].ReceiptLot.LotAttr08;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr08 = rfReceiptDetailInfo.LotAttr08;
                            }
                            execReceiptDetailInfo.ReceiptLot.LotAttr09 = rfReceiptDetailInfo.LotAttr09;
                            if ((lotTemplateInfo.RfLotAttr10Visible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotAttr10))
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr10 = receiptDetailInfos[i].ReceiptLot.LotAttr10;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.LotAttr10 = rfReceiptDetailInfo.LotAttr10;
                            }
                            if (lotTemplateInfo.RfProduceDateVisible != "Y")
                            {
                                execReceiptDetailInfo.ReceiptLot.ProduceDate = receiptDetailInfos[i].ReceiptLot.ProduceDate;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ProduceDate = rfReceiptDetailInfo.LotProduceDate;
                            }
                            if (lotTemplateInfo.RfExpiryDateVisible != "Y")
                            {
                                execReceiptDetailInfo.ReceiptLot.ExpiryDate = receiptDetailInfos[i].ReceiptLot.ExpiryDate;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ExpiryDate = rfReceiptDetailInfo.LotExpiryDate;
                            }
                            if ((lotTemplateInfo.RfExternalLotVisible != "Y") && string.IsNullOrEmpty(rfReceiptDetailInfo.LotExternalLot))
                            {
                                execReceiptDetailInfo.ReceiptLot.ExternalLot = receiptDetailInfos[i].ReceiptLot.ExternalLot;
                            }
                            else
                            {
                                execReceiptDetailInfo.ReceiptLot.ExternalLot = rfReceiptDetailInfo.LotExternalLot;
                            }
                        }
                        else
                        {
                            execReceiptDetailInfo.ReceiptLot.LotAttr01 = rfReceiptDetailInfo.LotAttr01;
                            execReceiptDetailInfo.ReceiptLot.LotAttr02 = rfReceiptDetailInfo.LotAttr02;
                            execReceiptDetailInfo.ReceiptLot.LotAttr03 = rfReceiptDetailInfo.LotAttr03;
                            execReceiptDetailInfo.ReceiptLot.LotAttr04 = rfReceiptDetailInfo.LotAttr04;
                            execReceiptDetailInfo.ReceiptLot.LotAttr05 = rfReceiptDetailInfo.LotAttr05;
                            execReceiptDetailInfo.ReceiptLot.LotAttr06 = rfReceiptDetailInfo.LotAttr06;
                            execReceiptDetailInfo.ReceiptLot.LotAttr07 = rfReceiptDetailInfo.LotAttr07;
                            execReceiptDetailInfo.ReceiptLot.LotAttr08 = rfReceiptDetailInfo.LotAttr08;
                            execReceiptDetailInfo.ReceiptLot.LotAttr09 = rfReceiptDetailInfo.LotAttr09;
                            execReceiptDetailInfo.ReceiptLot.LotAttr10 = rfReceiptDetailInfo.LotAttr10;
                            execReceiptDetailInfo.ReceiptLot.ProduceDate = rfReceiptDetailInfo.LotProduceDate;
                            execReceiptDetailInfo.ReceiptLot.ExpiryDate = rfReceiptDetailInfo.LotExpiryDate;
                            execReceiptDetailInfo.ReceiptLot.ExternalLot = rfReceiptDetailInfo.LotExternalLot;
                        }
                        execReceiptDetailInfo.ReceiptLot.ReceiptDate = DateTime.Now;
                        if (string.IsNullOrEmpty(receiptDetailInfos[i].VendorID))
                        {
                            execReceiptDetailInfo.ReceiptLot.VendorID = rfReceiptDetailInfo.VendorID;
                        }
                        else
                        {
                            execReceiptDetailInfo.ReceiptLot.VendorID = receiptDetailInfos[i].VendorID;
                        }
                        execReceiptDetailInfo.Remark = rfReceiptDetailInfo.Remark;
                        execReceiptDetailInfo.EffectiveDate = DateTime.Now;
                        execReceiptDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                        execReceiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                        execReceiptDetailInfo.FromLoc = execReceiptDetailInfo.ToLoc;
                        execReceiptDetailInfo.FromLpnID = execReceiptDetailInfo.ToLpnID;
                        execReceiptDetailInfoList.Add(execReceiptDetailInfo);
                    }
                }
                if (rfTotalReceivedQty > 0M)
                {
                    throw new Exception("收货数量大于单据数量,保存失败");
                }
                if ((execReceiptDetailInfoList != null) && (execReceiptDetailInfoList.Count > 0))
                {
                    result = new ReceiptDetailBLL(this.pubParasInfo).ExecuteReceiving(receiptInfo, execReceiptDetailInfoList);
                }
            }
            return !string.IsNullOrEmpty(result);
        }

        public bool ExecReceivingByLpn(string receiptID, List<RFReceiptDetailInfo> rfReceiptDetailInfos)
        {
            string whLoginID = this.dataBaseID[0];
            string receiptLineIDs = string.Empty;
            foreach (RFReceiptDetailInfo rfReceiptDetailInfo in rfReceiptDetailInfos)
            {
                receiptLineIDs = receiptLineIDs + "'" + rfReceiptDetailInfo.ReceiptLineID.ToString() + "',";
            }
            receiptLineIDs = receiptLineIDs.Substring(0, receiptLineIDs.Length - 1);
            string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving') AND RD.RECEIPT_LINE_ID IN (" + receiptLineIDs + ") ";
            ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, whLoginID, this.pubParasInfo);
            InboundHelper inboundHelper = new InboundHelper();
            ReceiptDetailBLL receiptDetailBLL = new ReceiptDetailBLL(this.pubParasInfo);
            List<ReceiptDetailInfo> receiptDetailInfos = null;
            if ((receiptInfo.ReceiptType == ReceiptTypes.Blind) || (rfReceiptDetailInfos[0].ReceiptType == ReceiptTypes.Blind))
            {
                if (rfReceiptDetailInfos[0].ReceiptType == ReceiptTypes.Blind)
                {
                    where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving' OR RD.STATUS = 'ReceivedComplete') AND RD.OWNER_ID = '" + rfReceiptDetailInfos[0].OwnerID + "' AND RD.SKU_ID = '" + rfReceiptDetailInfos[0].SkuID + "' ";
                    receiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                    if ((receiptDetailInfos != null) && (receiptDetailInfos.Count > 0))
                    {
                        rfReceiptDetailInfos[0].LotVendorID = receiptDetailInfos[0].ReceiptLot.VendorID;
                        if (!string.IsNullOrEmpty(receiptDetailInfos[0].VendorID))
                        {
                            rfReceiptDetailInfos[0].VendorID = receiptDetailInfos[0].VendorID;
                            rfReceiptDetailInfos[0].VendorName = receiptDetailInfos[0].VendorName;
                        }
                    }
                }
                ReceiptDetailInfo receiptDetailInfo = new ReceiptDetailInfo();
                receiptDetailInfo = this.ExchangeRfReceiptDetailInfo2ReceiptDetailInfo(rfReceiptDetailInfos[0], receiptDetailInfo, receiptDetailBLL, whLoginID);
                receiptDetailInfo.ReceiptLineID = commonMethod.GetMaxLineID("RECEIPT_DETAIL", receiptInfo.ReceiptID, whLoginID) + 10;
                receiptDetailInfo.ExternReceiptID = "";
                receiptDetailInfo.ExternLineID = "";
                receiptDetailInfo.PoID = "";
                receiptDetailInfo.PoLineID = 0;
                receiptDetailInfo.AltSkuID = "";
                receiptDetailInfo.EffectiveDate = DateTime.Now;
                receiptDetailInfo.QcRequired = "N";
                receiptDetailInfo.QcAutoAdjust = "N";
                receiptDetailInfo.EffectiveDate = DateTime.Now;
                receiptDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                receiptDetailInfo.CreatedDate = DateTime.Now;
                receiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                receiptDetailInfo.UpdatedDate = DateTime.Now;
                receiptDetailInfo.Remark = "Blind";
                decimal tmpReceivedQty = receiptDetailInfo.ReceivedQty;
                receiptDetailInfo.ReceivedQty = 0M;
                receiptDetailDA.InsertReceiptDetail(receiptDetailInfo, whLoginID);
                receiptDetailInfos = new List<ReceiptDetailInfo>();
                receiptDetailInfo.ReceivedQty = tmpReceivedQty;
                receiptDetailInfos.Add(receiptDetailInfo);
            }
            else
            {
                if (receiptInfo.IsPalletized == "Y")
                {
                    receiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                else
                {
                    receiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                foreach (RFReceiptDetailInfo rfReceiptDetailInfo in rfReceiptDetailInfos)
                {
                    foreach (ReceiptDetailInfo receiptDetailInfo in receiptDetailInfos)
                    {
                        if (rfReceiptDetailInfo.ReceiptLineID == receiptDetailInfo.ReceiptLineID)
                        {
                            this.ExchangeRfReceiptDetailInfo2ReceiptDetailInfo(rfReceiptDetailInfo, receiptDetailInfo, receiptDetailBLL, whLoginID);
                            break;
                        }
                    }
                }
            }
            string result = string.Empty;
            try
            {
                result = receiptDetailBLL.ExecuteReceiving(receiptInfo, receiptDetailInfos);
                DataSet ds = receiptDetailDA.GetReceivedLpnCount(receiptInfo.ReceiptID, whLoginID);
                if ((ds != null) && (ds.Tables.Count > 0))
                {
                    int receivedLpn = int.Parse(ds.Tables[0].Rows[0]["RECEIVED_LPN"].ToString());
                    int originalLpn = int.Parse(ds.Tables[1].Rows[0]["ORIGINAL_LPN"].ToString());
                    string status = ReceiptStatus.ReceivedComplete;
                    if (receivedLpn == 0)
                    {
                        status = ReceiptStatus.New;
                    }
                    else if ((receivedLpn > 0) && (receivedLpn < originalLpn))
                    {
                        status = ReceiptStatus.InReceiving;
                    }
                    else if (receivedLpn == originalLpn)
                    {
                        status = ReceiptStatus.ReceivedComplete;
                    }
                    receiptDA.UpdateReceiptStatus(receiptInfo.ReceiptID, status, whLoginID, this.pubParasInfo.UserID);
                }
            }
            catch (Exception ex)
            {
                if (receiptInfo.ReceiptType == ReceiptTypes.Blind)
                {
                    receiptDetailDA.DeleteReceiptDetail(new List<string> { receiptDetailInfos[0].ReceiptID }, new List<string> { receiptDetailInfos[0].ReceiptLineID.ToString() }, whLoginID);
                }
                throw new Exception(ex.Message);
            }
            if (string.IsNullOrEmpty(result))
            {
                return false;
            }
            return true;
        }

        public DataSet GetReceiptOrderInfo(string orderID, string where)
        {
            ReceiptQueryEntity receiptQuery = new ReceiptQueryEntity {
                IsGetAll = true,
                SortDirection = "DESC",
                SortField = "R.RECEIPT_ID"
            };
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(where))
            {
                sqlWhere.Add(where);
            }
            if (!string.IsNullOrEmpty(orderID))
            {
                sqlWhere.Add(" R.RECEIPT_ID = '" + orderID + "'");
            }
            sqlWhere.Add(" (R.STATUS = 'New' OR R.STATUS = 'InReceiving') ORDER BY R.RECEIPT_ID DESC ");
            return receiptDA.GetReceiptByQueryList(sqlWhere, receiptQuery, this.dataBaseID[0], this.pubParasInfo);
        }

        public RFPutawayInfo GetRFPutawayInfoByLpn(string lpnID)
        {
            string whLoginID = this.dataBaseID[0];
            RFPutawayInfo rfPutawayInfo = new RFPutawayInfo {
                LpnID = lpnID
            };
            List<RFPutawayDetailInfo> rfPutawayDetailInfos = receiptDetailDA.GetRFPutawayDetailInfoByLpn(lpnID, this.pubParasInfo.UserID, whLoginID);
            if ((rfPutawayDetailInfos != null) && (rfPutawayDetailInfos.Count > 0))
            {
                InboundHelper inboundHelper = new InboundHelper();
                rfPutawayInfo.RFPutawayDetailInfos = rfPutawayDetailInfos;
                ReceiptDetailBLL receiptDetailBll = new ReceiptDetailBLL(this.pubParasInfo);
                InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL();
                for (int i = 0; i < rfPutawayInfo.RFPutawayDetailInfos.Count; i++)
                {
                    List<ReceiptHistoryInfo> receiptHistoryInfoList = receiptDetailDA.GetReceiptHistoryInfoListByWhere(rfPutawayDetailInfos[i].ReceiptID, " IT.TO_LPN_ID = '" + lpnID + "' ", whLoginID);
                    if ((receiptHistoryInfoList != null) && (receiptHistoryInfoList.Count > 0))
                    {
                        for (int j = 0; j < receiptHistoryInfoList.Count; j++)
                        {
                            TaskDetailInfo taskDetailInfo;
                            PackInfo packInfo;
                            if ((rfPutawayInfo.RFPutawayDetailInfos[i].InvTransID == receiptHistoryInfoList[j].TransID) && string.IsNullOrEmpty(rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID))
                            {
                                string taskID = receiptDetailBll.GeneratePutAwayByReceiptHistory(receiptHistoryInfoList[j], inventoryMgtBll, this.pubParasInfo.UserID, whLoginID);
                                if (!string.IsNullOrEmpty(taskID))
                                {
                                    taskDetailInfo = taskDetailDA.GetTaskDetailByID(taskID, whLoginID, this.pubParasInfo);
                                    if (taskDetailInfo != null)
                                    {
                                        packInfo = packDA.GetPackByID(rfPutawayInfo.RFPutawayDetailInfos[i].PackID, whLoginID);
                                        rfPutawayInfo.RFPutawayDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, rfPutawayInfo.RFPutawayDetailInfos[i].UomID, rfPutawayInfo.RFPutawayDetailInfos[i].Qty, "R");
                                        rfPutawayInfo.ToLoc = taskDetailInfo.ToLoc;
                                        rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID = taskID;
                                        rfPutawayInfo.RFPutawayDetailInfos[i].FromLoc = taskDetailInfo.FromLoc;
                                    }
                                }
                            }
                            else if (!string.IsNullOrEmpty(rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID))
                            {
                                taskDetailInfo = taskDetailDA.GetTaskDetailByID(rfPutawayInfo.RFPutawayDetailInfos[i].TaskDetailID, whLoginID, this.pubParasInfo);
                                if (taskDetailInfo != null)
                                {
                                    packInfo = packDA.GetPackByID(rfPutawayInfo.RFPutawayDetailInfos[i].PackID, whLoginID);
                                    rfPutawayInfo.RFPutawayDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, rfPutawayInfo.RFPutawayDetailInfos[i].UomID, rfPutawayInfo.RFPutawayDetailInfos[i].Qty, "R");
                                    rfPutawayInfo.ToLoc = taskDetailInfo.ToLoc;
                                    rfPutawayInfo.RFPutawayDetailInfos[i].FromLoc = taskDetailInfo.FromLoc;
                                }
                            }
                        }
                    }
                }
                return rfPutawayInfo;
            }
            PublicMethod.GetInstance().ShowAlertMessage("F4200_023", this.pubParasInfo.UserLanguage);
            return rfPutawayInfo;
        }

        public RFReceiptDetailInfo GetRFReceiptDetailInfoByBarcodeAndLot(LotAttributeInfo lotAttributeInfo, string barcode)
        {
            string whLoginID = this.dataBaseID[0];
            string where = string.Empty;
            if (lotAttributeInfo != null)
            {
                if (!string.IsNullOrEmpty(lotAttributeInfo.OwnerID))
                {
                    where = where + " AND RD.OWNER_ID = '" + lotAttributeInfo.OwnerID + "'";
                }
                if (!string.IsNullOrEmpty(lotAttributeInfo.ExternalLot))
                {
                    where = where + " AND RD.EXTERNAL_LOT = '" + lotAttributeInfo.ExternalLot + "'";
                }
                if (!string.IsNullOrEmpty(lotAttributeInfo.LotAttr01))
                {
                    where = where + " AND RD.LOT_ATTR01 = '" + lotAttributeInfo.LotAttr01 + "'";
                }
                if (!string.IsNullOrEmpty(lotAttributeInfo.LotAttr10))
                {
                    where = where + " AND RD.RECEIPT_ID = '" + lotAttributeInfo.LotAttr10 + "'";
                }
            }
            return rfInboundDA.GetRFReceiptDetailInfoByBarcodeAndLot(barcode, where, whLoginID);
        }

        public List<RFReceiptDetailInfo> GetRFReceiptDetailInfoByLpn(string receiptID, string lpnID)
        {
            if (string.IsNullOrEmpty(lpnID))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_020", this.pubParasInfo.UserLanguage);
            }
            lpnID = lpnID.Replace("'", "''");
            string whLoginID = this.dataBaseID[0];
            string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving') AND (RD.LPN_ID = '" + lpnID + "' OR RD.CASE_ID = '" + lpnID + "') ";
            ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, whLoginID, this.pubParasInfo);
            List<RFReceiptDetailInfo> rfReceiptDetailInfos = null;
            List<ReceiptDetailInfo> receiptDetailInfos = null;
            if (receiptInfo.IsPalletized == "Y")
            {
                receiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
            }
            else
            {
                receiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
            }
            InboundHelper inboundHelper = new InboundHelper();
            if ((receiptDetailInfos != null) && (receiptDetailInfos.Count > 0))
            {
                rfReceiptDetailInfos = new List<RFReceiptDetailInfo>();
                RFReceiptDetailInfo rfReceiptDetailInfo = null;
                foreach (ReceiptDetailInfo receiptDetailInfo in receiptDetailInfos)
                {
                    rfReceiptDetailInfo = new RFReceiptDetailInfo {
                        RowID = receiptDetailInfo.RowID,
                        WhID = receiptDetailInfo.WhID,
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID,
                        OwnerID = receiptDetailInfo.OwnerID,
                        PoID = receiptDetailInfo.PoID,
                        PoLineID = receiptDetailInfo.PoLineID,
                        SkuID = receiptDetailInfo.SkuID,
                        SkuDescr = receiptDetailInfo.SkuDescr,
                        LpnID = receiptDetailInfo.LpnID,
                        CaseID = receiptDetailInfo.CaseID,
                        Status = receiptDetailInfo.Status,
                        StatusD = receiptDetailInfo.StatusD,
                        ReceivedDate = receiptDetailInfo.ReceivedDate,
                        AdjustedQty = receiptDetailInfo.AdjustedQty,
                        RejectedQty = receiptDetailInfo.RejectedQty
                    };
                    PackInfo packInfo = packDA.GetPackByID(receiptDetailInfo.PackID, whLoginID);
                    rfReceiptDetailInfo.ExpectedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.ExpectedQty, "R");
                    rfReceiptDetailInfo.ReceivedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.ReceivedQty, "R");
                    rfReceiptDetailInfo.UomID = receiptDetailInfo.UomID;
                    rfReceiptDetailInfo.PackID = receiptDetailInfo.PackID;
                    rfReceiptDetailInfo.ToLoc = receiptDetailInfo.ToLoc;
                    rfReceiptDetailInfo.ToLot = receiptDetailInfo.ToLot;
                    rfReceiptDetailInfo.ToLpnID = receiptDetailInfo.ToLpnID;
                    rfReceiptDetailInfo.ConditionCode = receiptDetailInfo.ConditionCode;
                    rfReceiptDetailInfo.VendorID = receiptDetailInfo.VendorID;
                    rfReceiptDetailInfo.VendorName = receiptDetailInfo.VendorName;
                    rfReceiptDetailInfo.LotAttr01 = receiptDetailInfo.ReceiptLot.LotAttr01;
                    rfReceiptDetailInfo.LotAttr02 = receiptDetailInfo.ReceiptLot.LotAttr02;
                    rfReceiptDetailInfo.LotAttr03 = receiptDetailInfo.ReceiptLot.LotAttr03;
                    rfReceiptDetailInfo.LotAttr04 = receiptDetailInfo.ReceiptLot.LotAttr04;
                    rfReceiptDetailInfo.LotAttr05 = receiptDetailInfo.ReceiptLot.LotAttr05;
                    rfReceiptDetailInfo.LotAttr06 = receiptDetailInfo.ReceiptLot.LotAttr06;
                    rfReceiptDetailInfo.LotAttr07 = receiptDetailInfo.ReceiptLot.LotAttr07;
                    rfReceiptDetailInfo.LotAttr08 = receiptDetailInfo.ReceiptLot.LotAttr08;
                    rfReceiptDetailInfo.LotAttr09 = receiptDetailInfo.ReceiptLot.LotAttr09;
                    rfReceiptDetailInfo.LotAttr10 = receiptDetailInfo.ReceiptLot.LotAttr10;
                    rfReceiptDetailInfo.LotProduceDate = receiptDetailInfo.ReceiptLot.ProduceDate;
                    rfReceiptDetailInfo.LotExpiryDate = receiptDetailInfo.ReceiptLot.ExpiryDate;
                    rfReceiptDetailInfo.LotReceiptDate = receiptDetailInfo.ReceiptLot.ReceiptDate;
                    rfReceiptDetailInfo.LotExternalLot = receiptDetailInfo.ReceiptLot.ExternalLot;
                    rfReceiptDetailInfo.LotVendorID = receiptDetailInfo.ReceiptLot.VendorID;
                    rfReceiptDetailInfo.Remark = receiptDetailInfo.Remark;
                    rfReceiptDetailInfos.Add(rfReceiptDetailInfo);
                }
                return rfReceiptDetailInfos;
            }
            PublicMethod.GetInstance().ShowAlertMessage("F4200_021", this.pubParasInfo.UserLanguage);
            return rfReceiptDetailInfos;
        }

        public RFReceiptInfo GetRFReceiptInfoByID(string receiptID)
        {
            RFReceiptInfo rfreceiptInfo = null;
            ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, this.dataBaseID[0], this.pubParasInfo);
            if (receiptInfo != null)
            {
                rfreceiptInfo = new RFReceiptInfo {
                    WhID = receiptInfo.WhID,
                    ReceiptID = receiptInfo.ReceiptID,
                    ReceiptType = receiptInfo.ReceiptType,
                    ReceiptDate = receiptInfo.ReceiptDate,
                    ExpectedReceiptDate = receiptInfo.ExpectedReceiptDate,
                    OwnerID = receiptInfo.OwnerID,
                    PoID = receiptInfo.PoID,
                    ExternalReceiptID = receiptInfo.ExternalReceiptID,
                    Status = receiptInfo.Status,
                    ArrivalDate = receiptInfo.ArrivalDate,
                    VendorID = receiptInfo.VendorID,
                    VendorName = receiptInfo.VendorName,
                    CarrierID = receiptInfo.CarrierID,
                    CarrierName = receiptInfo.CarrierName,
                    Remark = receiptInfo.Remark,
                    IsPalletized = receiptInfo.IsPalletized
                };
            }
            return rfreceiptInfo;
        }

        public RFReceiptInfo GetRFReceiptInfoByLpnID(string lpnID)
        {
            return rfInboundDA.GetRFReceiptInfoByLpnID(lpnID, this.dataBaseID[0]);
        }

        public RFReceiptValidationInfo GetRFReceiptValidationByAsnIDAndSkuBarCode(string receiptID, string ownerID, string skuBarCode)
        {
            return rfInboundDA.GetRFReceiptValidationByAsnIDAndSkuBarCode(receiptID, ownerID, skuBarCode, this.dataBaseID[0]);
        }

        public SkuInfo GetSkuInfoByDecompositionBarcode(string ownerID, string barcodeID)
        {
            string whLoginID = this.dataBaseID[0];
            string numberStr = "0123456789";
            string charStr = string.Empty;
            int blankIndex = 0;
            string decompositionBarcode = string.Empty;
            bool numberBarcode = true;
            string doubleBarcode = string.Empty;
            SkuInfo skuInfo = null;
            List<SkuInfo> skuInfos = skuDA.GetSkuInfosByOwnerIDAndBarCode(ownerID, barcodeID, whLoginID, this.pubParasInfo);
            if ((skuInfos != null) && (skuInfos.Count != 0))
            {
                doubleBarcode = "Y";
            }
            else
            {
                if (barcodeID.Length < 6)
                {
                    throw new Exception("条码解析出错：条码长度不足6位！");
                }
                blankIndex = barcodeID.IndexOf(" ");
                if (blankIndex > 0)
                {
                    decompositionBarcode = barcodeID.Substring(0, blankIndex);
                }
                if (decompositionBarcode == "")
                {
                    for (int i = 0; i < barcodeID.Length; i++)
                    {
                        charStr = barcodeID.Substring(i, 1);
                        if (numberStr.IndexOf(charStr) < 0)
                        {
                            numberBarcode = false;
                            break;
                        }
                    }
                    if (numberBarcode)
                    {
                        if (barcodeID.Length != 0x10)
                        {
                            if (barcodeID.Length != 11)
                            {
                                throw new Exception("条码解析出错：数字长度不符！");
                            }
                            decompositionBarcode = barcodeID.Substring(0, 6);
                        }
                        else
                        {
                            decompositionBarcode = barcodeID.Substring(2, 6);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(decompositionBarcode))
                {
                    skuInfos = skuDA.GetSkuInfosByOwnerIDAndBarCode(ownerID, decompositionBarcode, whLoginID, this.pubParasInfo);
                }
                else if (barcodeID.Length != 6)
                {
                    skuInfos = skuDA.GetSkuInfosByOwnerIDAndBarCode(ownerID, barcodeID.Substring(0, 6), whLoginID, this.pubParasInfo);
                    if ((skuInfos == null) || (skuInfos.Count != 1))
                    {
                        skuInfos = skuDA.GetSkuInfosByOwnerIDAndBarCode(ownerID, barcodeID.Substring(1, 6), whLoginID, this.pubParasInfo);
                    }
                }
                doubleBarcode = "N";
            }
            if ((skuInfos != null) && (skuInfos.Count == 1))
            {
                skuInfo = skuInfos[0];
                skuInfo.SkuStyle = doubleBarcode;
                return skuInfo;
            }
            if ((skuInfos != null) && (skuInfos.Count > 1))
            {
                throw new Exception("条码解析出错：条码重复！");
            }
            if ((skuInfos == null) || (skuInfos.Count == 0))
            {
                throw new Exception("条码解析出错：未找到对应货品！");
            }
            return skuInfo;
        }
    }
}

